package com.chen.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.common.Result;
import com.chen.mapper.ReportMapper;
import com.chen.pojo.Report;
import com.chen.pojo.Sign;
import com.chen.service.Impl.ReportServiceImpl;
import com.chen.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chen
 * @date 2022/5/5 11:41
 */
@RestController
@RequestMapping("/report")
@Api(value = "ReportController", tags = "举报操作")
public class ReportController {

    @Autowired
    private ReportServiceImpl reportService;

    @Resource
    private ReportMapper reportMapper;

    @PostMapping("/addReport")
    @ApiOperation("插入举报")
    public Result addReport(@RequestBody Report report) {
        return reportService.addReport(report);

    }

    @PostMapping("/updateReport")
    @ApiOperation("更新举报")
    public Result updateReport(@RequestBody Report report) {
        return reportService.addReport(report);

    }


    @GetMapping("/page")
    @ApiOperation("分页")
    public IPage<Report> findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize,
                                @RequestParam(defaultValue = "") String time ,
                                @RequestParam(defaultValue = "") String username ,
                                @RequestParam(defaultValue = "") String due){
        QueryWrapper<Report> queryWrapper=new QueryWrapper();
        IPage<Report> page=new Page<>(pageNum, pageSize);

        if(!"".equals(time)){
            queryWrapper.like("time", time);
        }
        if(!"".equals(username)){
            queryWrapper.like("username", username);
        }
        if(!"".equals(due)){
            queryWrapper.like("due", due);
        }
        queryWrapper.orderByDesc("id");

        IPage<Report> reportIPage = reportService.page(page, queryWrapper);


        return reportIPage;


    }

    @GetMapping("/findAll")
    @ApiOperation("分页")
    public  Result findAll(){
        return Result.success(reportService.getReportList());
    }

    @GetMapping("/select")
    @ApiOperation("分页")
    public  Result select(){

        List<Report> list = reportMapper.select();

        return Result.success(list);
    }


    @GetMapping("/selectReportName/{article_Name}")
    public Result selectReportName(@PathVariable("article_Name") String article_Name){
        return  Result.success(reportService.selectReportName(article_Name));
    }


}
